import 'package:flutter/material.dart';
import 'package:yzb_flutter/global/application.dart';


class Indicator extends StatelessWidget {

  final PageController pageController;
  final int itemCount;
  Indicator(this.pageController,this.itemCount):assert(pageController!=null);

  final Color normalColor = Color(Application.mColors.disableColor);
  final Color focusColor = Color(Application.mColors.primaryColor);
  final double dotSize = 8.0;
  final double space = 8.0;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: List<Widget>.generate(itemCount, (index){
          return _buildDotItem(index);
        }),

      ),
    );
  }

  Widget _buildDotItem(int index) {
    int current = pageController.page == null?0:pageController.page.round()%itemCount;
    return Container(
      height: dotSize,
      width: dotSize+space,
      child: Center(
        child: Material(
          type: MaterialType.circle,
          color: index == current?focusColor:normalColor,
          child: Container(
            width: dotSize,
            height: dotSize,
          ),
        ),
      ),
    );

  }

}

